package com.fmi.timedealer.moodtracking;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.fmi.timedealer.R;
import com.fmi.timedealer.datamanager.IDataManager;
import com.fmi.timedealer.datamanager.SQLiteDataManager;
import com.fmi.timedealer.moodgame.MoodGameActivity;

public class MoodManagementActivity extends Activity{
	
	private IDataManager dbManager;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mood_management);
		
		dbManager = new SQLiteDataManager("MyDB", this);
		
		setMoodIconAndLabel();
		Button btnUpdateMood = (Button) findViewById(R.id.btnUpdateMood);
		btnUpdateMood.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				Intent i = new Intent(MoodManagementActivity.this, UpdateMoodActivity.class);
				startActivity(i);
			}
		});
		
		Button btnMoodGame = (Button)findViewById(R.id.btnMoodGame);
		btnMoodGame.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				Intent i = new Intent(MoodManagementActivity.this, MoodGameActivity.class);
				startActivity(i);
			}
		});
	}
	
	private Mood getMoodByCode(int code) {
		
		Mood mood = null;
		for(Mood current : Mood.values()) {
			if(current.getCode() == code) {
				return current;
			}
		}
		return mood;
	}
	
	private void setMoodIconAndLabel() {
		ImageView moodIcon = (ImageView) findViewById(R.id.mood_icon);
		moodIcon.setImageResource(getMoodByCode(dbManager.getCurrentMoodCode()).getIcon());
		
		TextView lblCurrentMood = (TextView) findViewById(R.id.mood_label);
		lblCurrentMood.setText(getMoodByCode(dbManager.getCurrentMoodCode()).getLabel());
		
	}
	
	@Override
	public void onResume()
	{
		super.onResume();
		setMoodIconAndLabel();
	 }
}
